import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import style from './style/index.css'
// 导入vant
import Vant from 'vant';
import 'vant/lib/index.css';
import 'amfe-flexible'
import axios from 'axios'
import dayjs from 'dayjs'
// axios.defaults.baseURL = 'http://122.s51.249.55:3000/index.php/Api/'
const $axios = axios.create({
        baseURL: 'http://122.51.249.55:3000/index.php/Api/',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        transformRequest: [
            data => {
                let ret = "";
                for (let it in data) {
                    ret +=
                        encodeURIComponent(it) +
                        "=" +
                        encodeURIComponent(data[it]) +
                        "&";
                }
                return ret;
            }
        ]
    })
    // const $axios =
    // 拦截器
axios.interceptors.request.use(function(config) {
        if (config.url !== 'User/login') {
            console.log(config.url);
            const { token } = JSON.parse(sessionStorage.getItem('userinfo'))
            config.headers.Authorization = token
        }
        return config
    },
    function(err) {
        return Promise.reject(err)
    })

// // 添加响应拦截器
axios.interceptors.response.use(function(response) {
    // 对响应数据做点什么
    return response;
}, function(error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
// 过滤器
Vue.filter('formateTime', (val, str = "YYYY-MM-DD") => {
    return dayjs(val * 1000).format(str)
})
Vue.prototype.$axios = $axios
Vue.use(Vant);
Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')